home *** CD-ROM | disk | FTP | other *** search
/ The Fatted Calf / The Fatted Calf.iso / Applications / Utilities / Sentinel / Source / LockMgr.m < prev    next >
Encoding:
Text File  |  1994-05-23  |  3.1 KB  |  173 lines

  1.  
  2. /* Generated by Interface Builder */
  3.  
  4.  
  5. #import "LockMgr.h"
  6. #import "ScreenLock.h"
  7. #import <appkit/appkit.h>
  8.  
  9.  
  10. void idleTimerProc ( DPSTimedEntry teNumber, double now, char *userData )
  11. {
  12.     [ (id) userData idle ] ;
  13.     return ;
  14. }
  15.  
  16.  
  17. @implementation LockMgr
  18.  
  19. - init
  20. {
  21.     static NXDefaultsVector    SentinelDefaults =
  22.                             {
  23.                                 { "DimTime", "5" },
  24.                                 { "AutoLock", "NO" },
  25.                                 { "RequirePassword", "YES" },
  26.                                 { NULL }
  27.                             } ;
  28.  
  29.     NXRegisterDefaults ( "Sentinel", SentinelDefaults ) ;
  30.     maxIdleTime = atoi ( NXGetDefaultValue ( "Sentinel", "DimTime" ) ) ;
  31.     autoLock = ! strcmp (
  32.             NXGetDefaultValue ( "Sentinel", "AutoLock" ), "YES" ) ;
  33.     requirePassword = ! strcmp (
  34.             NXGetDefaultValue ( "Sentinel", "RequirePassword" ), "YES" ) ;
  35.     lastDimDestiny = 0 ;
  36.  
  37.     evsDriver = NXOpenEventStatus() ;
  38.  
  39.     timedEntry = DPSAddTimedEntry ( 60.0, (DPSTimedEntryProc) idleTimerProc,
  40.             (void *) self, NX_MODALRESPTHRESHOLD ) ;
  41.  
  42.     return [ super init ] ;
  43. }
  44.  
  45.  
  46. - free
  47. {
  48.     NXCloseEventStatus(evsDriver) ;
  49.     DPSRemoveTimedEntry ( timedEntry ) ;
  50.     return [ super free ] ;
  51. }
  52.  
  53.  
  54. - ok: sender
  55. {
  56.     char                idleString [ 4 ] ;
  57.     char                autoString [ 4 ] ;
  58.     char                pwordString [ 4 ] ;
  59.     NXDefaultsVector    SentinelDefaults =
  60.                         {
  61.                             { "DimTime", idleString },
  62.                             { "AutoLock", autoString },
  63.                             { "RequirePassword", pwordString },
  64.                             { NULL }
  65.                         } ;
  66.  
  67.     autoLock = [ autoLockSwitch intValue ] ;
  68.     requirePassword = [ requirePasswordSwitch intValue ] ;
  69.     maxIdleTime = [ idleSlider intValue ] ;
  70.  
  71.     sprintf ( idleString, "%d", maxIdleTime ) ;
  72.     strcpy ( autoString, autoLock ? "YES" : "NO" ) ;
  73.     strcpy ( pwordString, requirePassword ? "YES" : "NO" ) ;
  74.     NXWriteDefaults ( "Sentinel", SentinelDefaults ) ;
  75.  
  76.     [ revertButton setEnabled: NO ] ;
  77.     [ okButton setEnabled: NO ] ;
  78.     [ prefsPanel orderOut: self ] ;
  79.  
  80.     lastDimDestiny = 0 ;
  81.  
  82.     return self ;
  83. }
  84.  
  85.  
  86. - revert: sender
  87. {
  88.     [ autoLockSwitch setIntValue: autoLock ] ;
  89.     [ requirePasswordSwitch setIntValue: requirePassword ] ;
  90.     [ idleSlider setIntValue: maxIdleTime ] ;
  91.     [ idleField setIntValue: maxIdleTime ] ;
  92.     [ revertButton setEnabled: NO ] ;
  93.     [ okButton setEnabled: NO ] ;
  94.     [ prefsPanel makeKeyAndOrderFront: self ] ;
  95.  
  96.     lastDimDestiny = 0 ;
  97.  
  98.     return self ;
  99. }
  100.  
  101. - changeSetting: sender
  102. {
  103.     switch ( [ sender tag ] )
  104.     {
  105.         case 1:
  106.         {
  107.             [ idleField setIntValue:[ idleSlider intValue ] ] ;
  108.             break ;
  109.         }
  110.         
  111.         case 2:
  112.         {
  113.             [ idleSlider setIntValue:[ idleField intValue ] ] ;
  114.             break ;
  115.         }
  116.     }
  117.     [ revertButton setEnabled: YES ] ;
  118.     [ okButton setEnabled: YES ] ;
  119.     return self ;
  120. }
  121.  
  122.  
  123. - idle
  124. {
  125.     double    currentDimDestiny ;
  126.  
  127.     if ( [ screenLock isLocked ] )
  128.     {
  129.         idleTime = 0 ;
  130.         return self ;
  131.     }
  132.     
  133.     currentDimDestiny = NXAutoDimTime ( evsDriver ) ;
  134.     if ( currentDimDestiny < lastDimDestiny )
  135.     {
  136.         idleTime++ ;
  137.     }
  138.     else
  139.     {
  140.         idleTime = 0 ;
  141.     }
  142.     if ( ( autoLock ) && ( idleTime >= maxIdleTime ) )
  143.     {
  144.         [ screenLock lock: self ] ;
  145.     }
  146.     lastDimDestiny = currentDimDestiny ;
  147.     return self ;
  148. }
  149.  
  150.  
  151. - (BOOL) requirePassword
  152. {
  153.     return requirePassword ;
  154. }
  155.  
  156.  
  157. - (double) brightness
  158. {
  159.     double        theBrightness ;
  160.     
  161.     theBrightness = NXScreenBrightness(evsDriver) ;
  162.     return theBrightness ;
  163. }
  164.  
  165.  
  166. - setBrightness: (double) newBrightness
  167. {
  168.     NXSetScreenBrightness(evsDriver, newBrightness) ;
  169.     return self ;
  170. }
  171.  
  172. @end
  173.